package com.xbjtech.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.xbjtech.model.Order;
import com.xbjtech.model.OrderExample;
import com.xbjtech.model.OrderExample.Criteria;
import com.xbjtech.service.OrderService;
import com.xbjtech.util.SmsSend;
import com.xbjtech.util.SmsSendImpl;

@Controller("paidan")
@RequestMapping("admin/paidan")
public class PdController {

	@Autowired
	OrderService orderservice;
	
	

	@RequestMapping("sendlist")
	public String paiDan(@RequestParam(required = true, defaultValue = "1") Integer currentpage, Model model) {
		OrderExample example = new OrderExample();
		Criteria criteria = example.createCriteria();
		criteria.andDeletedNotEqualTo(1);
		PageInfo<Order> page = orderservice.selectOrderListPage(example, currentpage);
		model.addAttribute("page", page);

		return "admin/paidan/sendlist";
	}

	@RequestMapping("dispatcher/{id}")
	public String dispatcher(@PathVariable Long id, Model model) {
		Order order = orderservice.selectById(id);
		model.addAttribute("order", order);

		return "admin/paidan/dispatcher";
	}
	
	@RequestMapping("send")
	public String send(@RequestParam(required=true) String linkaddress ,String storeaddress,String storeid,String orderid,String storephone,String certifycode,Model model) {
		SmsSend smssend=new SmsSendImpl();
		Map<String, String> linkmap=new HashMap<String, String>();
		Map<String, String> storemap=new HashMap<String, String>();
		linkmap.put("code", certifycode);
		linkmap.put("name", storeid);
		linkmap.put("phone", storephone);
		linkmap.put("address", linkaddress);
		storemap.put("orderId", orderid);
		storemap.put("orderInfo", storeid);
		smssend.send("1", storephone, linkmap);
		smssend.send("2", storephone, storemap);
		
		
	return "redirect:/admin/paidan/sendlist";
	}
}
